/*
* @Author: tomystery
* @Date:   2017-09-08 18:09:46
* @Last Modified by:   tomystery
* @Last Modified time: 2017-09-30 16:40:49
*/
'use strict';
require('./index.css');
var templateIndex=require('./index.string');
require('page/common/nav/index.js');
var navSide=require('page/common/nav-side/index.js');
require('page/common/header/index.js');
var Pagination=require('util/pagination/index.js');
var _mm=require('util/mm.js');
var _order=require('service/order-service.js');


//page逻辑部分
var page={
	data:{
		listParam:{
			pageNum:1,
			pageSize:3
		}
	},
	init:function(){
		this.onLoad();
	},
	onLoad:function(){
		//初始化左侧菜单
		navSide.init({
			name:'order-list'
		});
		//加载用户信息
		this.loadOrderList();
	},
	//加载用户信息
	loadOrderList:function(){
		var _this=this;
		var orderListHtml='';
		var $listCon=$('.order-list-con');
		_order.getOrderList(this.data.listParam,function(res){

			//渲染html
			orderListHtml=_mm.renderHtml(templateIndex,res);
			$listCon.html(orderListHtml);
			
			//加载出pagination
				_this.loadPagination({
                hasPreviousPage : res.hasPreviousPage,
                prePage         : res.prePage,
                hasNextPage     : res.hasNextPage,
                nextPage        : res.nextPage,
                pageNum         : res.pageNum,
                pages           : res.pages
            });
		},function(errMsg){
			_mm.errorTips(errMsg);
			$listCon.html('<p class="err-tip">加载订单失败，请刷新后重试</p>');
		});
	},
	//加载分页信息
	loadPagination:function(pageInfo){
		var _this=this;
	this.pagination ? '':(this.pagination=new Pagination());//假设这个组件存在，把它new出来
	//封装一个组件有类和对象2种方式，这两种方式的区别：
	//如果有两个组件，通过new的方式则会使得两个组件相互干扰，但是通过对象的方式则不会
	this.pagination.render($.extend({},pageInfo,{
		container:$('.pagination'),
		onSelectPage:function(pageNum){
			_this.data.listParam.pageNum=pageNum;
			_this.loadOrderList();
		}
	}));

		
	}
};
	

$(function(){
	page.init();
})
